<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户id" prop="userInfoId">
        <el-input
          v-model="queryParams.userInfoId"
          placeholder="请输入用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入单位地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出差情况：是/否" prop="evection">
        <el-input
          v-model="queryParams.evection"
          placeholder="请输入出差情况：是/否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出差地点" prop="evectionPlace">
        <el-input
          v-model="queryParams.evectionPlace"
          placeholder="请输入出差地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任职部门" prop="department">
        <el-input
          v-model="queryParams.department"
          placeholder="请输入任职部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职务" prop="companyPost">
        <el-input
          v-model="queryParams.companyPost"
          placeholder="请输入职务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位级别：单位负责人/部门负责人/科室负责人/一般员工" prop="level">
        <el-input
          v-model="queryParams.level"
          placeholder="请输入岗位级别：单位负责人/部门负责人/科室负责人/一般员工"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="持有因公护照：是/否" prop="passport">
        <el-input
          v-model="queryParams.passport"
          placeholder="请输入持有因公护照：是/否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="曾去过哪里  填写字段" prop="haveBeen">
        <el-input
          v-model="queryParams.haveBeen"
          placeholder="请输入曾去过哪里  填写字段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位性质：机关单位/国有/外企/民营/个体私营/其他" prop="companyNature">
        <el-input
          v-model="queryParams.companyNature"
          placeholder="请输入单位性质：机关单位/国有/外企/民营/个体私营/其他"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="持有签证或曾经去过：美国/加拿大/英国/澳大利亚/新西兰/申根/日本/韩国/其他" prop="country">
        <el-input
          v-model="queryParams.country"
          placeholder="请输入持有签证或曾经去过：美国/加拿大/英国/澳大利亚/新西兰/申根/日本/韩国/其他"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作经历" prop="workExperience">
        <el-input
          v-model="queryParams.workExperience"
          placeholder="请输入工作经历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生活或人生阅历" prop="life">
        <el-input
          v-model="queryParams.life"
          placeholder="请输入生活或人生阅历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="companyRemark">
        <el-input
          v-model="queryParams.companyRemark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['kycinfo:work:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['kycinfo:work:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['kycinfo:work:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['kycinfo:work:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="workList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" width="55" align="center" label="序号" />
      <el-table-column label="客户号" align="center" prop="userInfoId" />
      <el-table-column label="单位名称" align="center" prop="companyName" />
      <el-table-column label="单位地址" align="center" prop="address" />
      <el-table-column label="出差情况：是/否" align="center" prop="evection" />
      <el-table-column label="出差地点" align="center" prop="evectionPlace" />
      <el-table-column label="任职部门" align="center" prop="department" />
      <el-table-column label="职务" align="center" prop="companyPost" />
      <el-table-column label="岗位级别：单位负责人/部门负责人/科室负责人/一般员工" align="center" prop="level" />
      <el-table-column label="持有因公护照：是/否" align="center" prop="passport" />
      <el-table-column label="曾去过哪里  填写字段" align="center" prop="haveBeen" />
      <el-table-column label="单位性质：机关单位/国有/外企/民营/个体私营/其他" align="center" prop="companyNature" />
      <el-table-column label="持有签证或曾经去过：美国/加拿大/英国/澳大利亚/新西兰/申根/日本/韩国/其他" align="center" prop="country" />
      <el-table-column label="工作经历" align="center" prop="workExperience" />
      <el-table-column label="生活或人生阅历" align="center" prop="life" />
      <el-table-column label="备注" align="center" prop="companyRemark" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:work:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:work:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userInfoId">
          <el-input v-model="form.userInfoId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="单位名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入单位名称" />
        </el-form-item>
        <el-form-item label="单位地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入单位地址" />
        </el-form-item>
        <el-form-item label="出差情况：是/否" prop="evection">
          <el-input v-model="form.evection" placeholder="请输入出差情况：是/否" />
        </el-form-item>
        <el-form-item label="出差地点" prop="evectionPlace">
          <el-input v-model="form.evectionPlace" placeholder="请输入出差地点" />
        </el-form-item>
        <el-form-item label="任职部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入任职部门" />
        </el-form-item>
        <el-form-item label="职务" prop="companyPost">
          <el-input v-model="form.companyPost" placeholder="请输入职务" />
        </el-form-item>
        <el-form-item label="岗位级别：单位负责人/部门负责人/科室负责人/一般员工" prop="level">
          <el-input v-model="form.level" placeholder="请输入岗位级别：单位负责人/部门负责人/科室负责人/一般员工" />
        </el-form-item>
        <el-form-item label="持有因公护照：是/否" prop="passport">
          <el-input v-model="form.passport" placeholder="请输入持有因公护照：是/否" />
        </el-form-item>
        <el-form-item label="曾去过哪里  填写字段" prop="haveBeen">
          <el-input v-model="form.haveBeen" placeholder="请输入曾去过哪里  填写字段" />
        </el-form-item>
        <el-form-item label="单位性质：机关单位/国有/外企/民营/个体私营/其他" prop="companyNature">
          <el-input v-model="form.companyNature" placeholder="请输入单位性质：机关单位/国有/外企/民营/个体私营/其他" />
        </el-form-item>
        <el-form-item label="持有签证或曾经去过：美国/加拿大/英国/澳大利亚/新西兰/申根/日本/韩国/其他" prop="country">
          <el-input v-model="form.country" placeholder="请输入持有签证或曾经去过：美国/加拿大/英国/澳大利亚/新西兰/申根/日本/韩国/其他" />
        </el-form-item>
        <el-form-item label="工作经历" prop="workExperience">
          <el-input v-model="form.workExperience" placeholder="请输入工作经历" />
        </el-form-item>
        <el-form-item label="生活或人生阅历" prop="life">
          <el-input v-model="form.life" placeholder="请输入生活或人生阅历" />
        </el-form-item>
        <el-form-item label="备注" prop="companyRemark">
          <el-input v-model="form.companyRemark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWork, getWork, delWork, addWork, updateWork } from "@/api/kycinfo/work";

export default {
  name: "Work",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      workList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userInfoId: null,
        companyName: null,
        address: null,
        evection: null,
        evectionPlace: null,
        department: null,
        companyPost: null,
        level: null,
        passport: null,
        haveBeen: null,
        companyNature: null,
        country: null,
        workExperience: null,
        life: null,
        companyRemark: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userInfoId: [
          { required: true, message: "用户id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listWork(this.queryParams).then(response => {
        this.workList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        workId: null,
        userInfoId: null,
        companyName: null,
        address: null,
        evection: null,
        evectionPlace: null,
        department: null,
        companyPost: null,
        level: null,
        passport: null,
        haveBeen: null,
        companyNature: null,
        country: null,
        workExperience: null,
        life: null,
        companyRemark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.workId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const workId = row.workId || this.ids
      getWork(workId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改工作及学习等情况";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.workId != null) {
            updateWork(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWork(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const workIds = row.workId || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + workIds + '"的数据项？').then(function() {
        return delWork(workIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/work/export', {
        ...this.queryParams
      }, `work_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
